//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "Actual360.h"
using namespace Cephei::QL::Times::Daycounters;
#include <gen/QL/Times/DayCounter.h>
using namespace Cephei::QL::Times;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Times::Daycounters::CActual360::CActual360 () : CDayCounter(CActual360::typeid)
{
    try
    {
#ifdef HANDLE
        _phActual360 = NULL;
#endif
        _ppActual360 = new boost::shared_ptr<QuantLib::Actual360> (new QuantLib::Actual360 ( ));
        SetDayCounter (boost::dynamic_pointer_cast<QuantLib::DayCounter> (*_ppActual360));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::Daycounters::CActual360::CActual360 (boost::shared_ptr<QuantLib::Actual360>& childNative, Object^ owner) : CDayCounter(CActual360::typeid)
{
#ifdef HANDLE
	_phActual360 = NULL;
#endif
	_ppActual360 = &childNative;
    _ppDayCounter = new boost::shared_ptr<QuantLib::DayCounter> (boost::dynamic_pointer_cast<QuantLib::DayCounter> (*_ppActual360));
}
Cephei::QL::Times::Daycounters::CActual360::CActual360 (QuantLib::Actual360& childNative, Object^ owner) : CDayCounter(CActual360::typeid)
{
#ifdef HANDLE
	_phActual360 = NULL;
#endif
	_ppActual360 = new boost::shared_ptr<QuantLib::Actual360> (&childNative);
    _ppDayCounter = new boost::shared_ptr<QuantLib::DayCounter> (boost::dynamic_pointer_cast<QuantLib::DayCounter> (*_ppActual360));
    _Actual360Owner = owner;
    _DayCounterOwner = owner;
}

Cephei::QL::Times::Daycounters::CActual360::CActual360 (CActual360^ copy) : CDayCounter(CActual360::typeid)
{
#ifdef HANDLE
	_phActual360 = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppActual360 = new boost::shared_ptr<QuantLib::Actual360> (copy->GetShared());
        _ppDayCounter = new boost::shared_ptr<QuantLib::DayCounter> (boost::dynamic_pointer_cast<QuantLib::DayCounter> (*_ppActual360));
    }
}
Cephei::QL::Times::Daycounters::CActual360::CActual360 (PLATFORM::Type^ t) : CDayCounter(CActual360::typeid)
{
#ifdef HANDLE
	_phActual360 = NULL;
#endif
	if (!t->IsSubclassOf(CActual360::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Times::Daycounters::CActual360::CActual360 (QuantLib::Handle<QuantLib::Actual360>& childNative, Object^ owner)  : CDayCounter(CActual360::typeid)
{
	_phActual360 = &childNative;
	_ppActual360 = &static_cast<boost::shared_ptr<QuantLib::Actual360>>(childNative.currentLink());
    _ppDayCounter = new boost::shared_ptr<QuantLib::DayCounter> (boost::dynamic_pointer_cast<QuantLib::DayCounter> (*_ppActual360));
    _Actual360Owner = owner;
}
Cephei::QL::Times::Daycounters::CActual360::CActual360 (QuantLib::Handle<QuantLib::Actual360> childNative)  : CDayCounter(CActual360::typeid)
{
	_phActual360 = &childNative;
	_ppActual360 = &static_cast<boost::shared_ptr<QuantLib::Actual360>>(childNative.currentLink());
    _ppDayCounter = new boost::shared_ptr<QuantLib::DayCounter> (boost::dynamic_pointer_cast<QuantLib::DayCounter> (*_ppActual360));
}
#endif
#ifdef STRUCT
Cephei::QL::Times::Daycounters::CActual360::CActual360 (QuantLib::Actual360 childNative)  : CDayCounter(CActual360::typeid)
{
#ifdef HANDLE
	_phActual360 = NULL;
#endif
	_ppActual360 = new boost::shared_ptr<QuantLib::Actual360> (new QuantLib::Actual360 (childNative));
    _ppDayCounter = new boost::shared_ptr<QuantLib::DayCounter> (boost::dynamic_pointer_cast<QuantLib::DayCounter> (*_ppActual360));
}
#endif

Cephei::QL::Times::Daycounters::CActual360::~CActual360 ()
{
    if (_ppActual360 != NULL)
    {
	    delete _ppActual360;
        _ppActual360 = NULL;
    }
}
Cephei::QL::Times::Daycounters::CActual360::!CActual360 ()
{
    if (_ppActual360 != NULL)
    {
	    delete _ppActual360;
    }
}
QuantLib::Actual360& Cephei::QL::Times::Daycounters::CActual360::GetReference ()
{
    if (_ppActual360 == NULL) throw REFNEW NativeNullException ();
	return **_ppActual360;
}
boost::shared_ptr<QuantLib::Actual360>& Cephei::QL::Times::Daycounters::CActual360::GetShared ()
{
    if (_ppActual360 == NULL) throw REFNEW NativeNullException ();
	return *_ppActual360;
}
QuantLib::Actual360* Cephei::QL::Times::Daycounters::CActual360::GetPointer ()
{
    if (_ppActual360 == NULL) throw REFNEW NativeNullException ();
	return &**_ppActual360;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::Actual360>& Cephei::QL::Times::Daycounters::CActual360::GetHandle ()
{
	if (_phActual360 == NULL)
	{
		_phActual360 = new Handle<QuantLib::Actual360> (*_ppActual360);
	}
	return *_phActual360;
}
#endif
bool Cephei::QL::Times::Daycounters::CActual360::HasNative () 
{
	return (_ppActual360 != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Times::Daycounters::IActual360^ Cephei::QL::Times::Daycounters::CActual360_Factory::Create ()
{
    return REFNEW CActual360 ();
}
